package com.inspur.s57.datacatalog.service.impl;

import com.inspur.s57.datacatalog.dao.DataAttributeDAO;
import com.inspur.s57.datacatalog.dao.TreeModelDao;
import com.inspur.s57.datacatalog.entity.DataAttribute;
import com.inspur.s57.datacatalog.entity.TreeModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class TreeModelServiceImpl {

    @Autowired
    TreeModelDao treeModelDao;
    @Autowired
    DataAttributeDAO dataAttributeDAO;

    /**
     * 按ID查找model信息
     * @param id
     * @return
     */
    public TreeModel getTreeModel(Integer id){
        Optional<TreeModel> treeModel=treeModelDao.findById(id);
        if (treeModel.isPresent()){
            return treeModel.get();
        }else {
            return null;
        }
    }

    /**
     * 保存model
     * @param treeModel
     */
    public TreeModel saveTreeModel(TreeModel treeModel){
        return treeModelDao.save(treeModel);
    }

    /**
     * 返回所有的model
     * @return
     */
    public List<TreeModel> listTreeModel(){
        return treeModelDao.findAll();
    }

    /**
     * 更新data属性。
     * @param data
     * @return
     */
    public List<DataAttribute> updateTree(List<DataAttribute> data){
       return dataAttributeDAO.saveAll(data);
    }

}
